package com.wechat.tencentwechatlogin.config;

import com.wechat.tencentwechatlogin.oauth.api.WechatApi;
import com.wechat.tencentwechatlogin.oauth.service.CustomOAuthService;
import org.scribe.builder.ServiceBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OAuthConfig {
    private static final String CALLBACK_URL = "http://localhost:8080/oauth/%s/callback";

    @Value("${oAuth.wechat.appId}")
    String weChatAppId;

    @Value("${oAuth.wechat.appSecret}")
    String weCHatSecret;



    @Bean
    public CustomOAuthService getWechatOAuthService(){
        return (CustomOAuthService) new ServiceBuilder()
                .provider(WechatApi.class)
                .apiKey(weChatAppId)
                .apiSecret(weCHatSecret)
                .callback(String.format(CALLBACK_URL,OAuthTypes.WECHAT))
                .build();
    }
}
